import qs from 'qs';
import AuthGuard from '../guard/auth-guard';
import { ViewRoute } from './view-route';
const indexRoute = [
{{#if app.defaultPSAppIndexView}}
    {
        path: '/index/',
        name: 'index',
        meta: {
            caption: '{{app.defaultPSAppIndexView.caption}}',
            tag: '{{app.defaultPSAppIndexView.codeName}}',
            requireAuth: false,
            ignoreAddPage: false,
            startPage: true,
            parameters: [
                { pathName: 'views', parameterName: 'index' },
            ],
        },
        beforeEnter: (to: any, from: any, next: any) => {
            to.defaultPage = true;
            const routerParamsName = 'index';
            const params: any = {};
            if (to.params && to.params[routerParamsName]) {
                Object.assign(params, qs.parse(to.params[routerParamsName], { delimiter: ';' }));
            }
            const url: string = '/appdata';
            const auth: Promise<any> = AuthGuard.getInstance().authGuard(url, params);
            auth.then((result: any) => {
                next(result ? true : false);
            }).catch(() => {
                next(false);
            })
        },
        component: () => import("@views/{{#if app.defaultPSAppIndexView.psAppModule.codeName}}{{spinalCase app.defaultPSAppIndexView.psAppModule.codeName}}/{{/if}}{{spinalCase app.defaultPSAppIndexView.codeName}}/{{spinalCase app.defaultPSAppIndexView.codeName}}.vue"),
        children: [
    {{#each app.pages as | page |}}
        {{#and (neq page.codeName app.defaultPSAppIndexView.codeName) (eq page.type 'APPINDEXVIEW')}}
            {
                path: 'views/{{lowerCase page.codeName}}',
                meta: {
                    caption: '{{page.caption}}',
                    tag: '{{page.codeName}}',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/{{#if page.psAppModule.codeName}}{{spinalCase page.psAppModule.codeName}}/{{/if}}{{spinalCase page.codeName}}/{{spinalCase page.codeName}}.vue"),
            },
        {{/and}}
    {{/each}}
            // todo 需替换成 首页引用视图  getAllRelatedPSAppViews 拿不到
            ...ViewRoute,
        ]
    },
{{/if}}
]

export const IndexRoute = indexRoute;